package model;

import java.io.BufferedReader;
import java.io.IOException;

import applet.molecule.Atom;

/**
 * The model of water molecule.
 * 
 * @see model.moleculeModel
 */
public class WaterMolecule extends MoleculeModel {

	/** the number of atoms in water molecule */
	public static final int ATOM_NUM = 3;

	/**
	 * Parse configuration file and generate the water molecule model.
	 * 
	 * @param reader the buffered reader accesses to configuration file.
	 * 
	 * @return water molecule model
	 * 
	 * @throws IOException if there is some IO exception occur
	 */
	public static WaterMolecule parseWater(BufferedReader reader) throws IOException {
		WaterMolecule water = new WaterMolecule();
		water.type = MoleculeType.WATER;
		
		// parse 'O'
		String line = reader.readLine();
		String[] split = line.trim().split("[\\s]+");
		water.list.add(new Atom("WO", Float.parseFloat(split[0]), Float
				.parseFloat(split[1]), Float.parseFloat(split[2])));
		
		// parse 'H'
		final int totalH = 2;
		for(int i = 0; i<totalH; i++){
			line = reader.readLine();
			split = line.trim().split("[\\s]+");
			water.list.add(new Atom("H", Float.parseFloat(split[0]), Float
					.parseFloat(split[1]), Float.parseFloat(split[2])));
		}
		
		/* unit 4's x, y,z coordinates, it's a special site which does not need
		to be represented in the final image */
		// need modified: format was not confirmed
		line = reader.readLine();
		
		return water;
	}

}
